/*
 * MainMenuButton.fx
 *
 * Created on Feb 21, 2010, 3:43:34 PM
 */
package com.gpsbuddy.components;

import javafx.scene.CustomNode;
import javafx.scene.Node;
import javafx.fxd.FXDNode;
import javafx.scene.text.Text;
import javafx.scene.Group;
import javafx.scene.text.Font;
import com.gpsbuddy.utils.Utils;
import javafx.scene.layout.HBox;
import javafx.geometry.VPos;
import com.gpsbuddy.graphics.frontMenuButtonUI;
import javafx.scene.paint.Color;
import javafx.geometry.HPos;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;

/**
 * @author jonycus
 */
public class MainMenuButton extends CustomNode {

    public var imageNode: FXDNode;
    public var label: String;
    var mainButtonNode = frontMenuButtonUI { }
    var text = Text {
                content: label;
                font: Font { size: 14; };
                fill: Color.DARKGRAY;
            }
    var vbox = HBox {
                content: [imageNode, text];
                nodeVPos: VPos.CENTER;
                hpos: HPos.CENTER;
                spacing: 20;
                layoutY: 5;
                layoutX: 5;
            }
    var group = Group {
                content: [mainButtonNode, vbox]
            }

    override protected function create(): Node {
        return group;
    }

    var op = 0.7;
    override var opacity = bind op;
    override def onMouseEntered = function (event) {
                Timeline {
                    keyFrames: [
                        KeyFrame {
                            time: 0s
                            values: op => 0.7 tween Interpolator.LINEAR;
                        }
                        KeyFrame {
                            time: 0.3s
                            values: op => 1.0 tween Interpolator.LINEAR;
                        }
                    ]
                }.play();
            }
    override def onMouseExited = function (event) {
                Timeline {
                    keyFrames: [
                        KeyFrame {
                            time: 0s
                            values: op => 1.0 tween Interpolator.LINEAR;
                        }
                        KeyFrame {
                            time: 0.3s
                            values: op => 0.7 tween Interpolator.LINEAR;
                        }
                    ]
                }.play();
            }
}
